<template>
	<view>
		<van-nav-bar title="卖出订单" left-text="返回" left-arrow @click-left="onClickLeft" />
		<view class="head">
			<van-tabs active="a">
				<van-tab title="未付款" name="a" >
					<view v-show="empty" style="margin: 100px auto;">
						<van-empty description="暂无订单" />
					</view>
					<!-- 正常订单已卖出未付款 -->
					<view style="margin-top: 20px;" v-for="(item,index) in saleOrder" :key="index" v-show="item.orderState==0">
						<view style="display: flex;margin-left: 30rpx;">
							<view style="width: 10%;">
								<img style="width: 50rpx;height: 50rpx;border-radius:100% ;"
									:src="item.userPhoto"
									alt="">
							</view>
							<view style="width: 70%;">
								{{item.userName}}
							</view>
							<view style="width: 20%;text-align: right;margin-right: 30rpx;color: darkorange;">
								未付款
							</view>
						</view>
						<view style="display: flex;margin-left: 30rpx;">
							<view class="">
								<img style="width: 100rpx;height: 100rpx;"
									:src="item.commodityImg"
									alt="">
							</view>
							<view class="">
								<view
									style="font-weight: bold; margin-left: 30rpx; width: 560rpx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis; ">
									{{item.commodityName}}
				 			</view>
								<view style="width: 590rpx;text-align: right;color: darkgrey;">
									实付：￥{{item.orderPrice}}
								</view>
							</view>
						</view>
						<view style="display: flex;margin-top: 10px;">
							<button @click="chat(item.buyerTel)" style="width: 90px;height:50rpx;font-size: 15px;line-height: 50rpx;" >联系买家</button>
							<button @click="chat(item.buyerTel)" style="width: 90px;height:50rpx;font-size: 15px;line-height: 50rpx;">通知付款</button>
						</view>
						<van-divider />
					</view>
					
					<!-- 拍卖订单已卖出未付款 -->
					<view style="margin-top: 20px;" v-for="(item,index) in saleauctionOrder" :key="index" v-show="item.orderState==0">
						<view style="display: flex;margin-left: 30rpx;">
							<view style="width: 10%;">
								<img style="width: 50rpx;height: 50rpx;border-radius:100% ;"
									:src="item.userPhoto"
									alt="">
							</view>
							<view style="width: 70%;">
								{{item.userName}}
							</view>
							<view style="width: 20%;text-align: right;margin-right: 30rpx;color: darkorange;">
								未付款
							</view>
						</view>
						<view style="display: flex;margin-left: 30rpx;">
							<view class="">
								<img style="width: 100rpx;height: 100rpx;"
									:src="item.commodityImg"
									alt="">
							</view>
							<view class="">
								<view
									style="font-weight: bold; margin-left: 30rpx; width: 560rpx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis; ">
									{{item.commodityName}}
							</view>
								<view style="width: 590rpx;text-align: right;color: darkgrey;">
									实付：￥{{item.dealmoney}}
								</view>
							</view>
						</view>
						<view style="display: flex;margin-top: 10px;">
							<button @click="chat(item.buyerTel)" style="width: 90px;height:50rpx;font-size: 15px;line-height: 50rpx;" >联系买家</button>
							<button @click="chat(item.buyerTel)" style="width: 90px;height:50rpx;font-size: 15px;line-height: 50rpx;">通知付款</button>
						</view>
						<van-divider />
					</view>


				</van-tab>
				<van-tab title="已付款" name="b">
					<view v-show="auctionempty" style="margin: 100px auto;">
						<van-empty description="暂无订单" />
					</view>
					<!-- 正常订单已卖出已付款 -->
					<view style="margin-top: 20px;" v-for="(item,index) in saleOrder" :key="index" v-show="item.orderState==1 || item.orderState==2">
						<view style="display: flex;margin-left: 30rpx;">
							<view style="width: 10%;">
								<img style="width: 50rpx;height: 50rpx;border-radius:100% ;"
									:src="item.userPhoto"
									alt="">
							</view>
							<view style="width: 70%;">
								{{item.userName}}
							</view>
							<view style="width: 20%;text-align: right;margin-right: 30rpx;color: darkorange;">
								已付款
							</view>
						</view>
						<view style="display: flex;margin-left: 30rpx;">
							<view class="">
								<img style="width: 100rpx;height: 100rpx;"
									:src="item.commodityImg"
									alt="">
							</view>
							<view class="">
								<view
									style="font-weight: bold; margin-left: 30rpx; width: 560rpx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis; ">
									{{item.commodityName}}
							</view>
								<view style="width: 590rpx;text-align: right;color: darkgrey;">
									实付：￥{{item.orderPrice}}
								</view>
							</view>
						</view>
						<view style="display: flex;margin-top: 10px;">
							<button @click="chat(item.buyerTel)" style="width: 90px;height:50rpx;font-size: 15px;line-height: 50rpx;">联系买家</button>
							<button @click="UploadLogistics(item)" style="width: 90px;height:50rpx;font-size: 15px;line-height: 50rpx;">上传物流</button>
						</view>
						<!-- <van-dialog use-slot title="上传物流" :show="showLogistics" show-cancel-button @confirm="getLogistics(item)"
							@cancel="CloseLogistics">
							<view style="display:flex">
								<view style="margin-left: 30rpx;">
									快递单号：
								</view>
								<input v-model="expressNumber" placeholder="请输入快递单号">
							</view>
						</van-dialog> -->
						<van-divider />
					</view>
					<van-dialog use-slot title="上传物流" :show="showLogistics" show-cancel-button @confirm="getLogistics"
						@cancel="CloseLogistics">
						<view style="display:flex">
							<view style="margin-left: 30rpx;">
								快递单号：
							</view>
							<input v-model="expressNumber" placeholder="请输入快递单号">
						</view>
					</van-dialog>
					
					<!-- 拍卖订单已卖出已付款 -->
					<view style="margin-top: 20px;" v-for="(item,index) in saleauctionOrder" :key="index" v-show="item.orderState!=0">
						<view style="display: flex;margin-left: 30rpx;">
							<view style="width: 10%;">
								<img style="width: 50rpx;height: 50rpx;border-radius:100% ;"
									:src="item.userPhoto"
									alt="">
							</view>
							<view style="width: 70%;">
								{{item.userName}}
							</view>
							<view style="width: 20%;text-align: right;margin-right: 30rpx;color: darkorange;">
								未付款
							</view>
						</view>
						<view style="display: flex;margin-left: 30rpx;">
							<view class="">
								<img style="width: 100rpx;height: 100rpx;"
									:src="item.commodityImg"
									alt="">
							</view>
							<view class="">
								<view
									style="font-weight: bold; margin-left: 30rpx; width: 560rpx;overflow: hidden;white-space: nowrap;text-overflow: ellipsis; ">
									{{item.commodityName}}
							</view>
								<view style="width: 590rpx;text-align: right;color: darkgrey;">
									实付：￥{{item.dealmoney}}
								</view>
							</view>
						</view>
						<view style="display: flex;margin-top: 10px;">
							<button @click="chat(item.buyerTel)" style="width: 90px;height:50rpx;font-size: 15px;line-height: 50rpx;" >联系买家</button>
							<button @click="UploadLogistics1(item)" style="width: 90px;height:50rpx;font-size: 15px;line-height: 50rpx;">上传物流</button>
						</view>
						
						<!-- <van-dialog use-slot title="上传物流" :show="showLogistics1" show-cancel-button @confirm="getLogistics1(item)"
							@cancel="CloseLogistics1">
							<view style="display:flex">
								<view style="margin-left: 30rpx;">
									快递单号：
								</view>
								<input v-model="expressNumber1" placeholder="请输入快递单号">
							</view>
						</van-dialog> -->
						
						<van-divider />
					</view>
					<van-dialog use-slot title="上传物流" :show="showLogistics1" show-cancel-button @confirm="getLogistics1"
						@cancel="CloseLogistics1">
						<view style="display:flex">
							<view style="margin-left: 30rpx;">
								快递单号：
							</view>
							<input v-model="expressNumber1" placeholder="请输入快递单号">
						</view>
					</van-dialog>
				</van-tab>
			</van-tabs>
		</view>
	</view>
</template>

<script>
	import { log } from 'util';
import request from '../../com/request.js'
	export default {
		data() {
			return {
				saleOrder: [{
					// num: 2,
					// tag: "标签",
					// price: 10.1,
					// desc: "商品描述",
					// title: "商品标题",
					// thumb: "https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83epKpyUQib2xIfKmq9ib4C9MNRpxkkyibfnVt9yH7oUDSFzia7ic8WJOUOGru1510s4Wwhr77s0wJFibdKpQ/132"
				}],
				saleauctionOrder:[],
				empty:true,
				auctionempty:true,
				showLogistics:false,
				expressNumber:"",
				showLogistics1:false,
				expressNumber1:"",
				wuliu:'',
				wuliu1:''
			}
		},
		methods: {
			onClickLeft() {
				uni.redirectTo({
					url: '/pages/MyCenter/MyCenter'
				});
			  },
			selectAuctionSaleOrder(){//查看拍卖卖出订单
				request({
					url: 'api/auctionSoldOrder/get',
					data: {
						acc: uni.getStorageSync("userTel")
					},
					success: (resp) => {
						this.saleauctionOrder=resp.data.data
						console.log(this.saleauctionOrder,206);
						this.saleauctionOrder.forEach( async item => {
						            if(item.orderState==0){
						            	this.empty=false
						            }
									if(item.orderState!=0){
						            	this.auctionempty=false
						            }
						        });
					}
				})
			},
			selectSaleOrder(){//查看正常卖出订单
				request({
					url: 'api/SaleOrder/get',
					data: {
						acc: uni.getStorageSync("userTel")
					},
					success: (resp) => {
						this.saleOrder=resp.data.data
						console.log(this.saleOrder,226)
						this.saleOrder.forEach( async item => {
						            if(item.orderState==0){
						            	this.empty=false
						            }
									if(item.orderState!=0){
										this.auctionempty=false
									}
						        });
					}
				})
			},
			UploadLogistics(item){
				this.showLogistics=true
				this.wuliu=item
			},
			getLogistics(){
				request({
					url: 'api/confirmUploadLogistics/get',
					data: {
						orderId: this.wuliu.orderId,
						expressNumber:this.expressNumber
					},
					success: (resp) => {
						uni.showToast({
							title: '上传成功',
						})
					}
				})
				this.showLogistics=false
			},
			CloseLogistics(){
				this.showLogistics=false
			},
			UploadLogistics1(item){
				this.showLogistics1=true
				this.wuliu=item
			},
			getLogistics1(){
				request({
					url: 'api/DetermineTheUpload/get',
					data: {
						auctionKnockdownId: this.wuliu1.auctionKnockdownId,
						expressNumber:this.expressNumber1
					},
					success: (resp) => {
						uni.showToast({
							title: '上传成功',
						})
					}
				})
				this.showLogistics1=false
			},
			CloseLogistics1(){
				this.showLogistics1=false
			},
			chat(userTel){
				uni.navigateTo({
					url:`/pages/chatpage/chatpage?receiverPhone=${userTel}`
				})
			}
		},
		onLoad(){
			this.selectAuctionSaleOrder()
			this.selectSaleOrder()
		}
	}
</script>

<style>
</style>
